package jsen.tool.ddd.adapter.infrastructure.specification.base;

import jsen.tool.ddd.adapter.infrastructure.specification.ISpecification;

/**
 * @author jsen
 * @date 2021/10/12
 */
public class FilterSpecification<T> extends CompositeSpecification<T> {
    private final ISpecification<T> realSpec;

    public FilterSpecification(ISpecification<T> realSpec) {
        this.realSpec = realSpec;
    }

    @Override
    public boolean isSatisfiedBy(SpecContext<T> t) {
        if (realSpec instanceof CompositeSpecification) {
            if (t.isNeedSpec((CompositeSpecification<?>) realSpec)) {
                return realSpec.isSatisfiedBy(t);
            }
            return true;
        }
        return realSpec.isSatisfiedBy(t);
    }
}
